module.exports = (sequelize, Sequelize) => {
  const User = sequelize.define('user', {
    id: {
      type: Sequelize.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    username: {
      type: Sequelize.STRING(50),
      allowNull: false,
      unique: true,
      validate: {
        notEmpty: true,
        len: [3, 50]
      }
    },
    email: {
      type: Sequelize.STRING(100),
      allowNull: false,
      unique: true,
      validate: {
        isEmail: true
      },
      field: 'email'
    },
    password: {
      type: Sequelize.STRING(100),
      allowNull: false
    },
    fullName: {
      type: Sequelize.STRING(50),
      allowNull: true,
      field: 'full_name'
    },
    avatar: {
      type: Sequelize.STRING(255),
      defaultValue: 'default-avatar.png'
    },
    bio: {
      type: Sequelize.TEXT,
      allowNull: true
    },
    role: {
      type: Sequelize.ENUM('user', 'admin'),
      defaultValue: 'user'
    },
    status: {
      type: Sequelize.ENUM('active', 'inactive', 'banned'),
      defaultValue: 'active'
    },
    lastLogin: {
      type: Sequelize.DATE,
      allowNull: true,
      field: 'last_login'
    }
  }, {
    timestamps: true,
    paranoid: true,
    underscored: true,
    indexes: [
      {
        unique: true,
        fields: ['email']
      },
      {
        unique: true,
        fields: ['username']
      }
    ]
  });

  return User;
};